package Java基础.Java类的初始化顺序.三个被动引用;

import org.junit.jupiter.api.Test;

public class SSClass {
    static {
        System.out.println("SSClass");
    }
}

class SuperClass extends SSClass {
    static {
        System.out.println("SuperClass init!");
    }

    public static int value = 123;

    public SuperClass() {
        System.out.println("init SuperClass");
    }
}

class SubClass extends SuperClass {
    static {
        System.out.println("SubClass init");//类的"初始化阶段"调用这段静态代码块;
    }

    static int a = 1;

    public SubClass() {
        System.out.println("init SubClass");
    }
}

class NotInitialization {
    //知识点: 只会触发直接定义静态字段的SuperClass的初始化阶段;
    @Test
    public void test1() {
        System.out.println(SubClass.value);
    }
    /*
    SSClass
    SuperClass init!
    123
     */

    @Test
    public void test2() {
        SubClass[] sca = new SubClass[10];  // 被动引用2
    }
    /*
    没有任何输出.
     */
}
